/*
8_Correlations.do

Makes correlations table for Appendix Table A1
"Human Capital and Climate Change", 
	by Noam Angrist, Kevin Winseck, Harry Patrinos, and Joshua Graff Zivin.
		
Inputs:
	Cleaned_ESS_withFirstStage.dta
Outputs:
	CorrelationsTable.tex

*/

global clustervar "cntryXlaw"

use "Cleaned_ESS_withFirstStage.dta", clear

drop if mi(minEdu)
* Drop if missing CSL data




gen conservatism = 1 - lrscale_recoded

label var eduyrs_wins "Years education"
label var hinctnta_recoded "Income decile"
label var conservatism "Conservatism"

* School on income and income on conservatism



correlate eduyrs_wins hinctnta_recoded if in_sample==1 & in_pooled==1
local cor1: display %9.3f r(C)[2,1]
correlate  conservatism hinctnta_recoded if in_sample==1 & in_pooled==1
local cor2: display %9.3f r(C)[2,1]
correlate  eduyrs_wins conservatism if in_sample==1 & in_pooled==1
local cor3: display %9.3f r(C)[2,1]

foreach var in eduyrs_wins hinctnta_recoded conservatism{
	reg `var' yrbrn  b2.cntry_numeric if in_sample==1 & in_pooled==1
	predict `var'_residualized, residuals
}

correlate eduyrs_wins_residualized hinctnta_recoded_residualized if in_sample==1 & in_pooled==1
local cor4: display %9.3f r(C)[2,1]
correlate  conservatism_residualized hinctnta_recoded_residualized if in_sample==1 & in_pooled==1
local cor5: display %9.3f r(C)[2,1]
correlate  eduyrs_wins_residualized conservatism_residualized if in_sample==1 & in_pooled==1
local cor6: display %9.3f r(C)[2,1]

* Appendix Table A1
file open tablefile using "CorrelationsTable.tex", write replace

file write tablefile "\begin{tabular}{lcccc}" _n
file write tablefile " & \multicolumn{2}{c}{Raw} & \multicolumn{2}{c}{Residualized} \\ " _n
file write tablefile " & Schooling & Conservatism & Schooling & Conservatism \\ \hline " _n 
file write tablefile "Income & `cor1' & `cor2' & `cor4' & `cor5' \\" _n
file write tablefile "Schooling &  & `cor3' &   & `cor6' \\" _n
file write tablefile "\end{tabular}"

file close tablefile
